package com.cta.jms;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class MessageProducer {

	private static final Logger LOG = LoggerFactory
			.getLogger(MessageProducer.class);

	protected JmsTemplate jmsTemplate;

	@Value(value="${pbx.id}")
	private String pbxid;
	
	public void sendMessages(final String payload) throws JMSException {

		jmsTemplate.send(new MessageCreator() {

			public Message createMessage(Session session) throws JMSException {

				Message message = session.createObjectMessage(new TransferObject(payload, pbxid));

				LOG.info("Sending message>> {}", payload);

				return message;

			}

		});

	}


	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}
}
